package countDownLatchTest;

import java.util.concurrent.*;

/**
 * @author zxs
 * @create 2021-03-31 17:08
 */
public class TeacherThread implements Runnable {
    @Override
    public void run() {
        System.out.println("考试开始了");
        long start = System.currentTimeMillis();

        CountDownLatch countDownLatch = new CountDownLatch(5);
        Semaphore semaphore = new Semaphore(2);
        ExecutorService executorService = Executors.newCachedThreadPool();

        executorService.execute(new StuThread(600, countDownLatch,semaphore));
        executorService.execute(new StuThread(2000, countDownLatch,semaphore));
        executorService.execute(new StuThread(500, countDownLatch,semaphore));
        executorService.execute(new StuThread(3000, countDownLatch,semaphore));
        executorService.execute(new StuThread(700, countDownLatch,semaphore));

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        System.out.println("考试结束了");
        System.out.println("考试用时：" + (end - start));

        executorService.shutdown();
    }

}
